<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%">
      <el-table-column prop="name" header-align="center" align="center" label="名称"></el-table-column>
      <el-table-column prop="ver" header-align="center" align="center" label="版本"></el-table-column>

      <el-table-column prop="number" header-align="center" align="center" label="版本号"></el-table-column>

      <el-table-column prop="android_link" header-align="center" align="center" label="安卓地址"></el-table-column>
      <el-table-column prop="ios_link" header-align="center" align="center" label="ios地址"></el-table-column>
      <el-table-column prop="download" header-align="center" align="center" label="下载页面"></el-table-column>
      <el-table-column prop="packge_size" header-align="center" align="center" label="文件大小"></el-table-column>
      <el-table-column prop="update_time" header-align="center" align="center" label="上传时间"></el-table-column>

      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import sysService from '../../../api/sysService'
import AddOrUpdate from './app-add-or-update'
export default {
  components: {
    AddOrUpdate
  },
  data () {
    return {
      dataForm: {
        paramKey: ''
      },
      dataList: [],
      pageIndex: 1,
      page: 1,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  filters: {
    // 管道
    removeTag (param) {
      let tags = param.replace(/<\/?.+?>/g, '')
      let final_fonts = tags.substr(0, 49)
      return final_fonts
    }
  },
  activated () { },
  created () { },
  mounted () {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    async getDataList () {
      this.dataList = []

      this.dataListLoading = true
      // 调用接口
      let res = await sysService.appConfigList()
      if (res && res.data.code == 200) {
        this.dataList = (res.data.page.list)
      }
      this.dataListLoading = false
    },

    // 新增 / 修改
    addOrUpdateHandle (row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row)
      })
    },
    deleteHandle (id) {
      this.$confirm(`确定删除?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        let res = await sysService.appConfigDel(id)
        if (res && res.data.code == 200) {
          this.getDataList()
          this.$message({
            message: '删除成功',
            type: 'success'
          })
        }
      })
    }
  }
}
</script>
